package xml.sax;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 * @author oldliu
 * @since 1.0
 */
public class BookHandler extends DefaultHandler {
    @Override
    public void startDocument() throws SAXException {
        System.out.println("文档开始了。。。");
    }

    @Override
    public void endDocument() throws SAXException {
        System.out.println("文档结束了。。。");
    }

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
        System.out.println("元素开始，元素："+qName);
        System.out.println("----属性：");
        for(int i=0;i<attributes.getLength();i++){
            System.out.println("\t\t"+attributes.getQName(i)+"="+attributes.getValue(i));
        }
    }

    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
        System.out.println(qName+"解析结束！");
    }

    @Override
    public void characters(char[] ch, int start, int length) throws SAXException {
        String str=new String(ch,start,length);
        System.out.println("节点的值："+str);
    }
}
